# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm/configs/u8500_defconfig

_flavor="postmarketos-stericsson"
pkgname=linux-$_flavor
pkgver=5.8
pkgrel=0
pkgdesc="Mainline kernel fork for ST-Ericsson NovaThor devices"
arch="armv7"
_carch="arm"
url="https://github.com/stericsson-mainline/linux"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native"
makedepends="bison findutils flex installkernel openssl-dev perl"

# Source
_tag=v${pkgver//_/-}-stericsson
source="
	$pkgname-$_tag.tar.gz::$url/archive/$_tag.tar.gz
	config-$_flavor.armv7
"
builddir="$srcdir/linux-${_tag#v}"

prepare() {
	default_prepare
	cp "$srcdir/config-$_flavor.$CARCH" .config
}

build() {
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION=$((pkgrel + 1 ))
}

package() {
	mkdir -p "$pkgdir"/boot
	make zinstall modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_PATH="$pkgdir"/boot \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_DTBS_PATH="$pkgdir"/usr/share/dtb
	rm -f "$pkgdir"/lib/modules/*/build "$pkgdir"/lib/modules/*/source

	install -D "$builddir"/include/config/kernel.release \
		"$pkgdir"/usr/share/kernel/$_flavor/kernel.release
}

sha512sums="a0971727404aaad70f9d1b670db9b0759a7e338fd647366918f145203347c546851b6cb242ef10b76f8060b09da3dbab5b163fddcecb26c8f0f35ea2afad23f0  linux-postmarketos-stericsson-v5.8-stericsson.tar.gz
55aa7a5d6a7a4b171450ac2bb896c7eccd47f05f75695045420b0e09dc55024466795c77a4e86d657a0b4fd0832e3d75dbf59620fda008f391c1438c2aba00db  config-postmarketos-stericsson.armv7"
